package com.dreamwhale.machinery.goods.controller;


import com.dreamwhale.machinery.config.DataResult;
import com.dreamwhale.machinery.goods.mapper.YxStoreProductMapper;
import com.dreamwhale.machinery.goods.service.ProjectSeekService;
import com.dreamwhale.machinery.user.entity.UserShop;
import com.dreamwhale.machinery.user.service.UserShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 找工程 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/projectSeek")
public class ProjectSeekController {

    @Autowired
    private UserShopService userShopService;
    @Resource
    private YxStoreProductMapper yxStoreProductMapper;


    @Resource
    private ProjectSeekService projectSeekService;

    /**
     * 查询配件商户
     *
     * @param
     * @return
     */
//    @RequestMapping("/selectUserShopsLike")
//    public DataResult selectUserShopsLike(Integer page, Integer limit, Integer type,
//                                          @Param("merchantName")String merchantName,
//                                          @Param("provinceCode")String provinceCode,
//                                          @Param("cityCode")String cityCode) {
//
//         PageHelper.startPage(page, limit, true);
//         List<UserShop> list = userShopService.selectUserShopsLike(merchantName, provinceCode, cityCode);
//         //查询店铺商品
//         for (UserShop userShop : list) {
//             QueryWrapper<YxStoreProduct> queryWrapper = new QueryWrapper<>();
//             queryWrapper.eq("is_show", 1).eq("is_del", 0).eq("mer_id", userShop.getId());
//
//             List<YxStoreProduct> lists = yxStoreProductMapper.selectList(queryWrapper);
//             if (!CollectionUtils.isEmpty(lists)) {
//                 Integer integer = lists.stream().map(YxStoreProduct::getSales).reduce(Integer::sum).get();
//                 userShop.setTotalSales(integer);
//             }
//         }
//        PageInfo<UserShop> pages = new PageInfo<>(list);
//        return DataResult.ok(pages);
//
//    }
    @RequestMapping("/getIndexInfo")
    public ResponseEntity<DataResult> getIndex(String city) {
        return ResponseEntity.ok(projectSeekService.getIndex(city));

    }


    /***
     * 配件商户的筛选
     */
    @RequestMapping("/queryConditionCommercialTenant")
    public ResponseEntity<DataResult> queryConditionCommercialTenant(
            @RequestParam(name = "str", defaultValue = "") String str,
            @RequestParam(name = "brandId", defaultValue = "") Integer brandId,
            @RequestParam(name = "city", defaultValue = "") String city,
            @RequestParam(name = "salesVolume", defaultValue = "") Integer salesVolume,
            Integer page, Integer limit) {

        return ResponseEntity.ok(projectSeekService.queryConditionCommercialTenant(str, brandId, city, salesVolume, page, limit));
    }

    /***
     * 获取商户详细信息
     */
    @RequestMapping("/queryMerchantDetails")
    public ResponseEntity<DataResult> queryMerchantDetails(Integer merchantId, Integer userId) {
        return ResponseEntity.ok(projectSeekService.queryMerchantDetails(merchantId, userId));
    }


}

